﻿using System;
using System.Collections.Generic;
using System.Web;

namespace WebMvc.App.Web.Default.IndexController
{
    public class IndexAction  : NFinal.BaseAction
	{
		public IndexAction(System.IO.TextWriter tw):base(tw){}
		public IndexAction(string fileName) : base(fileName) {}
        public struct __Index_users__
		{
			
			public int id;
			
			public string name_cn;
			
			public string name_en;
			
		}
		public struct __Index_cup__
		{
			
			public int id;
			
			public string name_cn;
			
			public string name_en;
			
		}
		public void Index(int a, string b, int c)
        {
            int id = 1;
            string name = "NFinal";
            string newName = "newName";

            LitJson.JsonData data = new LitJson.JsonData();
            data["re"]="a";
            	var __Index_count_con__ = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString.tiaojiu);
			__Index_count_con__.Open();
			var __Index_count_command__ = new MySql.Data.MySqlClient.MySqlCommand("delete from user where id=3;", __Index_count_con__);
			
			var count = __Index_count_command__.ExecuteNonQuery();
			__Index_count_con__.Close();
			;
            	var __Index_counts_con__ = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString.tiaojiu);
			__Index_counts_con__.Open();
			var __Index_counts_command__ = new MySql.Data.MySqlClient.MySqlCommand("update user set name=?newName where id=1;", __Index_counts_con__);
			
			var __Index_counts_parameters__=new MySql.Data.MySqlClient.MySqlParameter[1];
			
			__Index_counts_parameters__[1-1] = new MySql.Data.MySqlClient.MySqlParameter("?newName",MySql.Data.MySqlClient.MySqlDbType.VarChar,40);
			__Index_counts_parameters__[1-1].Value = newName;
			
			__Index_counts_command__.Parameters.AddRange(__Index_counts_parameters__);
			
			var counts = __Index_counts_command__.ExecuteNonQuery();
			__Index_counts_con__.Close();
			;
            	var __Index_uid_con__ = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString.tiaojiu);
			__Index_uid_con__.Open();
			var __Index_uid_command__ = new MySql.Data.MySqlClient.MySqlCommand("insert into user(name,pwd) values(?name,'123');select @@IDENTITY;", __Index_uid_con__);
			
			var __Index_uid_parameters__=new MySql.Data.MySqlClient.MySqlParameter[1];
			
			__Index_uid_parameters__[1-1] = new MySql.Data.MySqlClient.MySqlParameter("?name",MySql.Data.MySqlClient.MySqlDbType.VarChar,40);
			__Index_uid_parameters__[1-1].Value = name;
			
			__Index_uid_command__.Parameters.AddRange(__Index_uid_parameters__);
			
			var uid = int.Parse(__Index_uid_command__.ExecuteScalar().ToString());
			__Index_uid_con__.Close();
			;
            //调用数据库魔法函数,可在App/Web/Default/IndexController/Index.cs中生成相关的函数
            	var __Index_users_con__ = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString.tiaojiu);
            __Index_users_con__.Open();
			var users = new System.Collections.Generic.List<__Index_users__>();
            
			var __Index_users_command__ = new MySql.Data.MySqlClient.MySqlCommand("select * from tj_cup_type where id>?id", __Index_users_con__);
			
			var __Index_users_parameters__=new MySql.Data.MySqlClient.MySqlParameter[1];
			
			__Index_users_parameters__[1-1] = new MySql.Data.MySqlClient.MySqlParameter("?id",MySql.Data.MySqlClient.MySqlDbType.Int32);
			__Index_users_parameters__[1-1].Value = id;
			
			__Index_users_command__.Parameters.AddRange(__Index_users_parameters__);
			
			var __Index_users_reader__= __Index_users_command__.ExecuteReader();
			if (__Index_users_reader__.HasRows)
			{
				while (__Index_users_reader__.Read())
				{
					var __Index_users_temp__ = new __Index_users__();
					
					if(!__Index_users_reader__.IsDBNull(1-1)){__Index_users_temp__.id = __Index_users_reader__.GetInt32(1-1);}
					
					if(!__Index_users_reader__.IsDBNull(2-1)){__Index_users_temp__.name_cn = __Index_users_reader__.GetString(2-1);}
					
					if(!__Index_users_reader__.IsDBNull(3-1)){__Index_users_temp__.name_en = __Index_users_reader__.GetString(3-1);}
					users.Add(__Index_users_temp__);
				}
			}
			__Index_users_reader__.Close();
			__Index_users_con__.Close();
			;
            	var __Index_cup_con__ = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString.tiaojiu);
            __Index_cup_con__.Open();
			var cup = new __Index_cup__();
            
			var __Index_cup_command__ = new MySql.Data.MySqlClient.MySqlCommand("select * from tj_cup_type where id=?id", __Index_cup_con__);
			
			var __Index_cup_parameters__=new MySql.Data.MySqlClient.MySqlParameter[1];
			
			__Index_cup_parameters__[1-1] = new MySql.Data.MySqlClient.MySqlParameter("?id",MySql.Data.MySqlClient.MySqlDbType.Int32);
			__Index_cup_parameters__[1-1].Value = id;
			
			__Index_cup_command__.Parameters.AddRange(__Index_cup_parameters__);
			
			var __Index_cup_reader__= __Index_cup_command__.ExecuteReader();
			if (__Index_cup_reader__.HasRows)
			{
				__Index_cup_reader__.Read();

				cup = new __Index_cup__();
				
				if(!__Index_cup_reader__.IsDBNull(1-1)){cup.id = __Index_cup_reader__.GetInt32(1-1);}
				
				if(!__Index_cup_reader__.IsDBNull(2-1)){cup.name_cn = __Index_cup_reader__.GetString(2-1);}
				
				if(!__Index_cup_reader__.IsDBNull(3-1)){cup.name_en = __Index_cup_reader__.GetString(3-1);}
				
			}
			__Index_cup_reader__.Close();
			__Index_cup_con__.Close();;
            	var __Index_name1_con__ = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString.tiaojiu);
			__Index_name1_con__.Open();
			var __Index_name1_command__ = new MySql.Data.MySqlClient.MySqlCommand("select name from user where id=?id", __Index_name1_con__);
			
			var __Index_name1_parameters__=new MySql.Data.MySqlClient.MySqlParameter[1];
			
			__Index_name1_parameters__[1-1] = new MySql.Data.MySqlClient.MySqlParameter("?id",MySql.Data.MySqlClient.MySqlDbType.Int32);
			__Index_name1_parameters__[1-1].Value = id;
			
			__Index_name1_command__.Parameters.AddRange(__Index_name1_parameters__);
			
			var name1 = new NFinal.DB.SqlObject(__Index_name1_command__.ExecuteScalar()).ToString();
			__Index_name1_con__.Close();
			;

            string text = "欢迎使用NFinal框架.";
            //调用模板
            
			Write("<!doctype html><html><head><script src=\"");
			Write(app);
			Write("Content/js/jquery-1.11.2.min.js\"></script><link href=\"");
			Write(app);
			Write("Content/css/frame.css\" type=\"text/css\" rel=\"stylesheet\" /></head><body>");
			Write("\r\n<header>\r\n    NFinal框架:这是头\r\n</header><article> Default Template <table><tr><td>");
			Write(text);
			Write("</td></tr></table><table><tr><td> id </td><td> name_cn </td></tr>");
			foreach(var u in users){
				Write("<tr><td>");
				Write(u.id);
				Write("</td><td>");
				Write(u.name_cn);
				Write("</td></tr>");
			}
			Write("</table><p><span>");
			Write(cup.id);
			Write("</span><span>");
			Write(cup.name_cn);
			Write("</span><span>");
			Write(cup.name_en);
			Write("</span></p></article>");
			Write("\r\n<footer>\r\n     NFinal框架.这是尾\r\n</footer></body></html>");
        }
        
        
        private void Add()
        {
          
        }
    }
}